// 引入 vue  路由
import Vue from 'vue'
import Router from 'vue-router'
// 引入 store
// import store from '../store'
// 引入页面组件
// import Login from '../views/login/login.vue'
import Registe from '../views/login/registe'
import Home from '../views/home'
import Category from '../views/category'
import Cart from '../views/cart'
import MyPage from '../views/myPage'
import SubCtegory from '@/views/category/subCategory'
import userLogin from '@/views/login/userLogin'
// 导入公共的组件
// import TabBur from '../common/tab-bar'

// 插件注册
Vue.use(Router)
// Redirected when going from "/login" to "/home" via a navigation guard.
// 对Router 中push 方法进行重写
const pushPlugin = Router.prototype.push
Router.prototype.push = function (paramas) {
  pushPlugin.call(this, paramas).catch(e => {
    console.log('屏蔽这个错误')
  })
}
// 实例化路由
const router = new Router({
  // 指定路由模式
  mode: 'history',
  routes: [
    { path: '/', redirect: '/userLogin' },
    // { path: '/login', component: Login, meta: { noLogin: true } },
    { path: '/userLogin', component: userLogin, meta: { noLogin: true, title: '登录页面' } },
    { path: '/registe', component: Registe },
    { path: '/subCtegory', component: SubCtegory },
    { path: '/home', component: Home, meta: { ico: 'icon-gouwuche', title: '首页' } },
    { path: '/category', component: Category, meta: { ico: 'icon-gouwuche', title: '分类' } },
    { path: '/cart', component: Cart, meta: { ico: 'icon-wodedingdan', title: '购物车' } },
    { path: '/myPage', component: MyPage, meta: { ico: 'icon-shouye', title: '我的' } }
  ]
})
router.beforeEach(function (to, from, next) {
// 免登录
  if (to.meta.noLogin) {
    next()
  }
  // 用户是否登录用户权限
  // const token = store.getters['common/getToken']
  // console.log(token, '----token')
  // if (token) {
  //   next()
  // } else {
  //   next('/userLogin')
  // }
  next()
})
export default router
